﻿<template>
    <div class="person1" style="width:99%;margin-top:-25px;">
        <!-- 查询条件 -->
        <div class="query-box">
            <el-form :model="dataForm" status-icon ref="dataForm">
                <el-row>
                    <el-col :span="4">
                        <el-form-item label prop="userName">
                            <el-input v-model="dataForm.userName" placeholder="请输入">
                                <template slot="prepend">用户名</template>
                            </el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="4">
                        <el-form-item label prop="contact">
                            <el-input v-model="dataForm.contact" placeholder="请输入">
                                <template slot="prepend">联系人</template>
                            </el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="4">
                        <el-form-item label prop="phone">
                            <el-input v-model="dataForm.phone" placeholder="请输入">
                                <template slot="prepend">联系电话</template>
                            </el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="4">
                        <el-form-item label prop="accountStatus">
                            <div class="depart-box">
                                <div class="slect-title">角色类型</div>
                                <el-select
                                    v-model="dataForm.roleId"
                                    filterable
                                    clearable
                                    placeholder="请选择角色类型"
                                >
                                    <el-option
                                        v-for="item in roles"
                                        :key="item.id"
                                        :label="item.roleName"
                                        :value="item.id"
                                    ></el-option>
                                </el-select>
                            </div>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="4">
                        <!-- <el-form-item label prop="phone">
              <el-input
                v-model="dataForm.systemUserId"
                placeholder="请输入"
              >
                <template slot="prepend">对应大区经理</template>
              </el-input>
                        </el-form-item>-->
                        <el-form-item label prop="accountStatus">
                            <div class="depart-box">
                                <div class="slect-title">对应大区经理</div>
                                <el-select v-model="dataForm.systemUserId" clearable filterable>
                                    <el-option
                                        v-for="item in userName"
                                        :key="item.id"
                                        :label="item.realName"
                                        :value="item.id"
                                    ></el-option>
                                </el-select>
                            </div>
                        </el-form-item>
                    </el-col>
                    <el-col :span="4">
                        <!-- <el-form-item label prop="schoolDictId">
              <el-input v-model="dataForm.schoolDictId" placeholder="请输入">
                <template slot="prepend">关联学校</template>
              </el-input>
                        </el-form-item>-->
                        <el-form-item label prop="accountStatus">
                            <div class="depart-box">
                                <div class="slect-title">关联学校</div>
                                <el-select v-model="dataForm.schoolDictCode" clearable filterable>
                                    <el-option
                                        v-for="item in school_option"
                                        :key="item.id"
                                        :label="item.schoolName"
                                        :value="item.schoolCode"
                                    >{{ item.schoolName }}</el-option>
                                </el-select>
                            </div>
                        </el-form-item>
                    </el-col>
                    <el-col :span="4">
                        <el-form-item label prop="accountStatus">
                            <div class="depart-box">
                                <div class="slect-title">状态</div>
                                <el-select v-model="dataForm.userStatus" clearable>
                                    <el-option
                                        v-for="item in accountStatus"
                                        :key="item.key"
                                        :label="item.value"
                                        :value="item.key"
                                    ></el-option>
                                </el-select>
                            </div>
                        </el-form-item>
                    </el-col>
                </el-row>
            </el-form>
            <div class="from-btns">
                <kt-button
                    :label="$t('action.reset')"
                    perms="true"
                    type="primary"
                    @click="resetForm()"
                />
                <kt-button :label="$t('action.search')" perms="true" @click="searchForm" />
            </div>
        </div>
        <!-- 新增用户,导出按钮 -->
        <div class="add-btns">
            <kt-button
                :label="$t('action.add')"
                perms="Organization:Person:add"
                type="primary"
                @click="handleAdd"
            />
            <kt-button
                :label="$t('action.exportExcel')"
                perms="Organization:Person:exportExcel"
                @click="exportPerson"
                type="primary"
            />
        </div>
        <!--表格内容栏-->
        <crm-table
            class="table-width"
            tripartiteMange
            permsEdit="Organization:Person:edit"
            permsDeletePartment="Organization:Person:deletePartment"
            permsResetPass="Organization:Person:resetPass"
            permsRelationSchool="Organization:Person:resetPass"
            permsBind="Organization:Person:resetPass"
            permsBindStudentDataFrom="Organization:Person:bindStudentDataFrom"
            :data="pageResult"
            :columns="columns"
            :show-overflow-tooltip="false"
            @findPage="findPage"
            @handleBindManager="handleBindManager"
            @handleEdit="handleEdit"
            @handleResetpass="handleResetpass"
            @changeSwitch="changeSwitch"
            :loading="loading"
            @handleRelationSchool="handleRelationSchool"
            @bindStudentDataFrom="bindStudentDataFrom"
        ></crm-table>

        <!--新增编辑界面-->
        <el-dialog
            class="add-pop personBox"
            :title="operation ? '新增三方账户' : '编辑'"
            width="30%"
            :visible.sync="dialogVisible"
            :close-on-click-modal="false"
        >
            <el-form
                :model="dataFormAdd"
                label-width="100px"
                :rules="operation?dataFormRules:dataFormRulesEdit"
                ref="dataFormAdd"
                :size="size"
                label-position="right"
            >
                <el-form-item label="用户名" prop="userName">
                    <el-input
                        v-model="dataFormAdd.userName"
                        :disabled="operation ? false : true"
                        placeholder="请输入"
                        auto-complete="off"
                    ></el-input>
                </el-form-item>
                <el-form-item label="三方名称" prop="threePartName">
                    <el-input
                        v-model="dataFormAdd.threePartName"
                        placeholder="请输入"
                        auto-complete="off"
                    ></el-input>
                </el-form-item>
                <el-form-item label="联系人" prop="contact">
                    <el-input v-model="dataFormAdd.contact" placeholder="请输入" auto-complete="off"></el-input>
                </el-form-item>
                <el-form-item label="联系电话" prop="phone">
                    <el-input v-model="dataFormAdd.phone" placeholder="请输入" auto-complete="off"></el-input>
                </el-form-item>
                <el-form-item label="角色类型" prop="roleId">
                    <el-select
                        v-model="dataFormAdd.roleId"
                        filterable
                        clearable
                        placeholder="请选择角色类型"
                    >
                        <el-option
                            v-for="item in roles"
                            :key="item.id"
                            :label="item.roleName"
                            :value="item.id"
                        ></el-option>
                    </el-select>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button :size="size" @click.native="dialogVisible = false">
                    {{
                    $t("action.cancel")
                    }}
                </el-button>
                <el-button
                    :size="size"
                    type="primary"
                    @click.native="submitForm"
                    v-if="!dataFormAdd.id"
                    :loading="editLoading"
                >{{ $t("action.submit") }}</el-button>
                <el-button
                    :size="size"
                    type="primary"
                    @click.native="submitFormEdit"
                    v-if="dataFormAdd.id"
                    :loading="editLoading"
                >{{ $t("action.submit") }}</el-button>
            </div>
        </el-dialog>
        <!-- 重置密码 -->
        <el-dialog
            class="resetpassword"
            title="重置密码"
            width="30%"
            :visible.sync="resetVisible"
            :close-on-click-modal="false"
        >
            <el-form label-width="110px" :rules="dataFormRules" ref="password" :model="dataFormAdd">
                <el-form-item label="用户名" prop="userName">
                    <el-input v-model="dataFormAdd.userName" :disabled="true" auto-complete="off"></el-input>
                </el-form-item>
                <el-form-item class="resetpassword-pass" label="密码" prop="resetpassword">
                    <el-input
                        v-model="dataFormAdd.userPassword"
                        type="text"
                        auto-complete="off"
                        style="width: 50%;margin-right: 10%;margin-left: 1%"
                    ></el-input>
                    <kt-button
                        :label="$t('action.autopassword')"
                        @click="autopassword"
                        perms="Organization:Person:resetPass"
                        type="primary"
                    />
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button :size="size" @click.native="resetVisible = false">
                    {{
                    $t("action.cancel")
                    }}
                </el-button>
                <el-button
                    :size="size"
                    type="primary"
                    @click.native="resetPwd"
                    :loading="editLoading"
                >{{ $t("action.submit") }}</el-button>
            </div>
        </el-dialog>
        <!--绑定大区经理-->
        <el-dialog
            class="add-pop personBox"
            title="绑定大区经理"
            width="30%"
            :visible.sync="managerAddVisible"
            :close-on-click-modal="false"
            @close="managerAddClose"
        >
            <el-form
                :model="managerAdd"
                label-width="100px"
                :rules="dataFormRules"
                ref="dataFormAdd"
                :size="size"
                label-position="right"
            >
                <el-form-item label="用户名">
                    <el-input
                        v-model="managerAdd.userName"
                        :disabled="true"
                        placeholder="请输入"
                        auto-complete="off"
                    ></el-input>
                </el-form-item>
                <el-form-item label="三方名称">
                    <el-input
                        v-model="managerAdd.threePartName"
                        :disabled="true"
                        placeholder="请输入"
                        auto-complete="off"
                    ></el-input>
                </el-form-item>
                <el-form-item label="选择部门">
                    <div class="schoolBoxContItemInput">
                        <el-select
                            v-model="managerAdd.departId"
                            @change="managerAddDeaprtChange"
                            filterable
                            placeholder="请选择"
                            value-key="id"
                            style="width: 100%;"
                        >
                            <el-option
                                v-for="item in departId_option"
                                :key="item.id"
                                :label="item.deptName"
                                :value="item.id"
                            ></el-option>
                        </el-select>
                    </div>
                </el-form-item>
                <el-form-item label="大区经理">
                    <div class="schoolBoxContItemInput">
                        <el-select
                            v-model="managerAdd.systemUserId"
                            filterable
                            @change="managerAddUserChange"
                            placeholder="请选择"
                            value-key="id"
                            style="width: 100%;"
                        >
                            <el-option
                                v-for="item in userName"
                                :key="item.id"
                                :label="item.realName"
                                :value="item.id"
                            ></el-option>
                        </el-select>
                    </div>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button :size="size" @click.native="managerAddVisible = false">
                    {{
                    $t("action.cancel")
                    }}
                </el-button>
                <el-button
                    :size="size"
                    type="primary"
                    @click.native="submitBindManger"
                    :loading="editLoading"
                >{{ $t("action.submit") }}</el-button>
            </div>
        </el-dialog>
        <!--关联学校-->
        <el-dialog
            title="关联学校"
            width="45%"
            :visible.sync="schoolAddVisible"
            :close-on-click-modal="false"
            :before-close="CancelAddPopSelect"
        >
            <el-form
                :model="schoolAdd"
                :rules="dataFormRules"
                ref="dataFormAdd"
                :size="size"
                label-position="right"
            >
                <el-row style="margin-bottom:20px">
                    <el-col :span="8">
                        <div class="depart-box">
                            <div class="slect-title" style="line-height: 40px;">学校编码：</div>
                            <el-select
                                filterable
                                clearable
                                v-model="schoolAdd.schoolCode"
                                placeholder="请选择"
                            >
                                <el-option
                                    v-for="item in school_option"
                                    :key="item.id"
                                    :label="item.schoolCode"
                                    :value="item.schoolCode"
                                >{{ item.schoolCode }}</el-option>
                            </el-select>
                        </div>
                    </el-col>
                    <el-col :span="9">
                        <div class="depart-box">
                            <div
                                class="slect-title"
                                style="line-height: 40px;margin-left:30px"
                            >学校名称：</div>
                            <el-select
                                filterable
                                clearable
                                v-model="schoolAdd.schoolName"
                                placeholder="请选择"
                            >
                                <el-option
                                    v-for="item in school_option"
                                    :key="item.id"
                                    :label="item.schoolName"
                                    :value="item.schoolName"
                                >{{ item.schoolName }}</el-option>
                            </el-select>
                        </div>
                    </el-col>
                    <el-col :span="2">
                        <el-button type="primary" @click="searchCenterList">查询</el-button>
                    </el-col>
                </el-row>
                <Crm-table
                    associationSchoolA
                    :border="true"
                    :showBatchDelete="false"
                    class="table-width"
                    permsAdd="Organization:TripartiteMange:AssociationSchoolA"
                    width="400"
                    permsSee="true"
                    @handleSeeA="handleSeeA"
                    :data="pageResultA"
                    :columns="columnsA"
                    :loading="loading"
                    @findPage="findPage2"
                ></Crm-table>
                <h1 class="columnsA-title">已选学校</h1>
                <Crm-table
                    :border="true"
                    associationSchoolB
                    :order="false"
                    :showBatchDelete="false"
                    class="table-width"
                    permsDelete="Organization:TripartiteMange:AssociationSchoolB"
                    width="400"
                    permsSee="true"
                    @handleSeeB="handleSeeB"
                    :data="pageResultB"
                    :columns="columnsA"
                    :loading="loading"
                    style="margin-bottom:20px;"
                ></Crm-table>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button :size="size" @click="CancelAddPopSelect">取 消</el-button>
                <el-button
                    type="primary"
                    :loading="editLoading"
                    :size="size"
                    @click="SubmitAddPopSelect"
                >保存</el-button>
            </div>
        </el-dialog>
        <el-dialog
            title="绑定学生客户来源"
            :visible.sync="studentDataFrom"
            width="30%"
            center
            @close='closeStudentDataFrom'
        >
            <div class="depart-box" style='width:300px;margin:0 auto'>
                <div class="slect-title" style="margin-top:10px">客户来源：</div>
                <el-cascader
                    clearable
                    filterable
                    multiple
                    :key="is_cascader"
                    v-model="studentDataFromValue"
                    :props="addressProps"
                    :options="resources_Options2"
                    change-on-select = false
                    placeholder="客户来源"
                ></el-cascader>
            </div>
            <span slot="footer" class="dialog-footer">
                <el-button size='mini' @click="closeStudentDataFrom ">取 消</el-button>
                <el-button size='mini' type="primary" @click="submitStudentDataFrom">确 定</el-button>
            </span>
        </el-dialog>
    </div>
</template>
<script>
import PopupTreeInput from "@/components/PopupTreeInput";
import KtButton from "@/views/Core/KtButton";
import CrmTable from "@/views/Core/CrmTable";
import QueryBox from "@/views/Core/QueryBox";
import CrmSwitch from "@/views/Core/CrmSwitch";
import axios from "axios";
import { baseUrl } from "@/utils/global";
import { isMobile } from "@/utils/validate";
export default {
    name: "Person",
    components: {
        PopupTreeInput,
        CrmTable,
        KtButton,
        QueryBox,
        CrmSwitch
    },
    data() {
        return {
            size: "small",
            filters: {
                name: ""
            },
            dataForm: {
                // oneLevelDeptId:'',
                // twoLevelDeptId:'',
                // threeLevelDeptId:''
            },
            exportPersonUrl: baseUrl + "/frontUserManager/export", //导出地址
            resetpassword: "",
            page: "person",
            columns: [
                { type: "index", label: "序号", minWidth: 50 },
                { prop: "userName", label: "编码/用户名", minWidth: 80 },
                { prop: "threePartName", label: "三方名称", minWidth: 100 },
                { prop: "roleName", label: "角色类型", minWidth: 100 },
                { prop: "contact", label: "联系人", minWidth: 100 },
                { prop: "studentDataFromName", label: "学生客户来源", minWidth: 100 },   
                { prop: "phone", label: "联系电话", minWidth: 100 },
                {
                    prop: "systemUserName",
                    label: "对应大区经理",
                    minWidth: 100
                },
                { prop: "schoolDictIdName", label: "关联学校", minWidth: 100 }
            ],
            columnsA: [
                { type: "index", label: "序号", minWidth: 50 },
                { prop: "schoolCode", label: "学校编码", minWidth: 100 },
                { prop: "schoolName", label: "学校名称", minWidth: 100 }
            ],
            pageRequest: { pageNum: 1, pageSize: 10 },
            pageResult: {
                content: [],
                totalSize: ""
            },
            operation: false, // true:新增, false:编辑
            dialogVisible: false, // 新增编辑界面是否显示
            managerAddVisible: false, //绑定大区经理显示界面
            editLoading: false,
            loading: false, // 加载标识
            resetVisible: false,
            schoolAddVisible: false,
            roles: [],
            // resetpassForm:pageResult,
            dataFormRules: {
                userName: [
                    { required: true, message: "请输入用户名", trigger: "blur" }
                ],
                threePartName: [
                    {
                        required: true,
                        message: "请输入三方名称",
                        trigger: "blur"
                    }
                ],
                contact: [
                    { required: true, message: "请输入联系人", trigger: "blur" }
                ],
                phone: [
                    {
                        required: true,
                        message: "请输入联系电话",
                        trigger: "blur"
                    }
                ],
                roleId: [
                    { required: true, message: "请选择角色", trigger: "blur" }
                ]
            },
            // 编辑  角色类型
            dataFormRulesEdit: {
                userName: [
                    {
                        required: false,
                        message: "请输入用户名",
                        trigger: "blur"
                    }
                ],
                threePartName: [
                    {
                        required: true,
                        message: "请输入三方名称",
                        trigger: "blur"
                    }
                ],
                contact: [
                    { required: true, message: "请输入联系人", trigger: "blur" }
                ],
                phone: [
                    {
                        required: true,
                        message: "请输入联系电话",
                        trigger: "blur"
                    }
                ],
                roleId: [
                    { required: true, message: "请选择角色", trigger: "blur" }
                ]
            },
            // 新增编辑界面数据
            dataFormAdd: {
                userName: "",
                realName: "",
                oneLevelDeptId: "",
                twoLevelDeptId: "",
                threeLevelDeptId: "",
                roleId: "",
                phone: "",
                email: "",
                demoAccount: "",
                accountStatus: "",
                duty: "",
                acccountPassword: "",
                userType: 1,
                isControlResource: ""
            },
            deptData: [],
            deptTreeProps: {
                label: "name",
                children: "children"
            },
            accountStatus: [], //状态下拉框
            duty: [], //职务下拉框
            isControlResource: [
                {
                    value: "是",
                    key: "1"
                },
                {
                    value: "否",
                    key: "2"
                }
            ],
            userDerpatName: "",
            managerAdd: {
                departmentId: "",
                systemUserIdname: "",
                systemUserId: "",
                departId: ""
            },
            schoolAdd: {
                schoolCode: "",
                schoolName: ""
            },
            userName: [],
            departId_option: [],
            pageResultA: {
                content: []
            },
            pageResultB: {
                content: []
            },
            school_option: [],
            SubmitAddPopSelectData: {
                id: "",
                schoolIds: []
            },
            managerAddUserSelect: false,
            studentDataFrom: false,
            addressArr: [], //绑定的数据
            is_cascader: Math.random(), //重新渲染标识key
            addressProps: {
                label: "codeValue",
                value: "codeKey",
                multiple: true,
                lazy: true, //开启异步加载
                lazyLoad(node, resolve) {
                    const { value, level } = node;
                    axios
                        .get(baseUrl + "/code/queryStudentDataFromByGroupId", {
                            params: { id: node.value }
                        })
                        .then(res => {
                            let response = res.data;

                            if (response.result == 1) {
                                resolve(
                                    response.data.map(item => {
                                        item.label = item.label;
                                        item.value = item.codeKey;
                                        item.leaf = "leaf"; //这个必须加，就是让组件识别是不是最后一级
                                        return item;
                                    })
                                );
                            }
                        });
                }
            },
            addressInit: false, //标记组件第一级数据开始加载没有
            studentDataFromValue: "",
            resources_Options2: []
        };
    },
    beforeMount: function() {
        this.$api.dropdown.studentDataFromGroup().then(res => {
            if (res.result == 1) {
                this.resources_Options = res.keyValueList;
                let arr = res.keyValueList;
                this.resources_Options2 = arr.map(item => {
                    item.codeValue = item.value;
                    item.codeKey = item.key;
                    return item;
                });
            }
        });
    },
    methods: {
        bindStudentDataFrom(row) {
            this.studentDataFrom = !this.studentDataFrom;
            this.studentDataFromId=row.row.id
        },
        closeStudentDataFrom(){
          this.studentDataFrom = false;
          this.studentDataFromValue=''
        },
        submitStudentDataFrom(){
          let arry=[]
          if(this.studentDataFromValue.length>0){
            this.studentDataFromValue.forEach(item=>{
              arry.push(item[1])
            })
          }
          this.$api.student
          .bindStudentDataFrom({
              id:this.studentDataFromId,
              studenDataFromCode:arry.join(',')
          })
          .then(res => {
              if (res.result == 2) {
                  this.$message({ message: res.msg, type: 'error' });
              } else {
                  this.$message({ message: res.msg, type: 'success' });
                  this.studentDataFromValue=''
                  this.studentDataFrom = false;
                  this.findPage(null)
              }
          });
        },
        //获取下拉框
        findDown: function() {
            this.queryRole();
            this.$api.dropdown.accountStatus().then(res => {
                this.accountStatus = res.keyValueList;
            });
            this.$api.dropdown.systemDuty().then(res => {
                this.duty = res.keyValueList;
            });
            this.$api.dropdown.users().then(res => {
                if (res.result == 1) {
                    this.userName = res.userInfoList;
                }
            });
            this.$api.dropdown.deptLevel3().then(res => {
                this.departId_option = res.departmentInfoList;
            });
            // 获取学校
            this.$api.oem.schoolList().then(res => {
                this.school_option = res.data;
            });
        },
        // 获取分页数据
        findPage: function(data) {
            console.log(data);
            setTimeout(
                function() {
                    if (data !== null) {
                        this.loading = true;
                        this.pageRequest = data.pageRequest;
                    }
                    this.dataForm.pageSize = this.pageRequest.pageSize;
                    this.dataForm.pageNum = this.pageRequest.pageNum;
                    this.dataForm.userType = 1;
                    this.$api.person
                        .findFontPage(this.dataForm)
                        .then(res => {
                            if (res.result == 2) {
                                this.$message({
                                    message: res.msg,
                                    type: "error"
                                });
                            } else {
                                this.pageResult.content = res.data;
                                this.pageResult.totalSize = res.total;
                                this.loading = false;
                                this.pageResult.content.forEach(item => {
                                    item.schoolDictIdName = "";
                                    if (item.schoolDictId) {
                                        item.schoolDictId
                                            .split(",")
                                            .forEach(
                                                (schoolDictIdItem, index) => {
                                                    if (
                                                        this.school_option
                                                            .length != 0
                                                    ) {
                                                        this.school_option.forEach(
                                                            SchoolItem => {
                                                                if (
                                                                    SchoolItem.id ==
                                                                    schoolDictIdItem
                                                                ) {
                                                                    if (
                                                                        index ==
                                                                        item.schoolDictId.split(
                                                                            ","
                                                                        )
                                                                            .length -
                                                                            1
                                                                    ) {
                                                                        item.schoolDictIdName +=
                                                                            SchoolItem.schoolName;
                                                                    } else {
                                                                        item.schoolDictIdName +=
                                                                            SchoolItem.schoolName +
                                                                            ",";
                                                                    }
                                                                }
                                                            }
                                                        );
                                                    }
                                                }
                                            );
                                    }
                                    // if (this.userName) {
                                    // 查询部门下的大区经理
                                    this.userName.forEach(userItem => {
                                        if (userItem.id === item.systemUserId) {
                                            item.systemUserIdName =
                                                userItem.realName;
                                        }
                                    });
                                    // }
                                });
                            }
                        })
                        .then(data != null ? data.callback : "");
                }.bind(this),
                0
            );
        },
        findPage2(data) {
            if (data !== null) {
                this.loading = true;
                this.pageRequest2 = data.pageRequest;
            }
            this.pageRequest2 = Object.assign(
                {},
                this.pageRequest2,
                this.schoolAdd
            );
            this.$api.school.schoolDictPageList(this.pageRequest2).then(res => {
                this.loading = false;
                let content = {
                    content: res.data,
                    totalSize: res.total
                };
                this.pageResultA = content;
                if (this.pageResultB.content.length > 0) {
                    this.pageResultB.content.forEach(item => {
                        this.pageResultA.content.forEach((j, i) => {
                            if (item.id == j.id) {
                                this.pageResultA.content.splice(i, 1);
                            }
                        });
                    });
                }
            });
        },
        searchCenterList() {
            this.loading = true;
            this.pageRequest2.pageNum = 1;
            this.findPage2(null);
        },
        handleDeleteSteering: function(params) {
            this.steeringData.isControlBranch = 2;
            this.steeringData.id = params.row.systemUserId;
            this.$confirm("确认删除选中数据吗？", "提示", {
                type: "warning"
            }).then(() => {
                this.$api.student
                    .updateIsUserBranchType(this.steeringData)
                    .then(res => {
                        if (res.result == 1) {
                            this.$message({
                                message: res.msg,
                                type: "success"
                            });
                            this.findPage(null);
                        } else {
                            this.$message({
                                message: res.msg,
                                type: "error"
                            });
                        }
                    });
            });
        },
        handleSeeA(params) {
            this.pageResultB.content.push(params.row);
            this.removeObjWithArr(this.pageResultA.content, params.row);
        },
        removeObjWithArr(_arr, _obj) {
            var length = _arr.length;
            for (var i = 0; i < length; i++) {
                if (this.isObjectValueEqual(_arr[i], _obj)) {
                    if (i == 0) {
                        _arr.shift(); //删除并返回数组的第一个元素
                        return;
                    } else if (i == length - 1) {
                        _arr.pop(); //删除并返回数组的最后一个元素
                        return;
                    } else {
                        _arr.splice(i, 1); //删除下标为i的元素
                        return;
                    }
                }
            }
        },
        isObjectValueEqual(a, b) {
            if (typeof a != "object" && typeof b != "object") {
                if (a == b) {
                    return true;
                } else {
                    return false;
                }
            }
            var aProps = Object.getOwnPropertyNames(a);
            var bProps = Object.getOwnPropertyNames(b);

            if (aProps.length != bProps.length) {
                return false;
            }

            for (var i = 0; i < aProps.length; i++) {
                var propName = aProps[i];

                if (a[propName] !== b[propName]) {
                    return false;
                }
            }
            return true;
        },
        handleSeeB(params) {
            this.pageResultA.content.push(params.row);
            this.removeObjWithArr(this.pageResultB.content, params.row);
        },
        // 关闭 学校绑定
        CancelAddPopSelect() {
            this.pageResultB.content.splice(0, this.pageResultB.content.length);
            this.schoolAddVisible = false;
            this.schoolAdd.schoolCode = "";
            this.schoolAdd.schoolName = "";
        },
        // 绑定学校 保存
        SubmitAddPopSelect() {
            this.editLoading = true;
            this.SubmitAddPopSelectData.id = this.SubmitAddPopSelectDataId;
            let branchIds = [];
            this.pageResultB.content.forEach(item => {
                branchIds.push(item.id);
            });
            this.SubmitAddPopSelectData.schoolIds = branchIds;
            this.$api.person
                .bindFontSchools(this.SubmitAddPopSelectData)
                .then(res => {
                    if (res.result == 1) {
                        this.$message({
                            message: "绑定成功！",
                            type: "success"
                        });
                        this.SteeringPop = false;
                        this.schoolAddVisible = false;
                        this.SubmitAddPopSelectData.branchIds = [];
                        this.schoolAdd.schoolCode = "";
                        this.schoolAdd.schoolName = "";
                        this.findPage(null);
                        this.pageResultB.content.splice(
                            0,
                            this.pageResultB.content.length
                        );
                    } else {
                        this.$message({
                            message: res.msg,
                            type: "error"
                        });
                    }
                    this.editLoading = false;
                });
        },
        //重置
        resetForm: function() {
            this.dataForm = {};
            this.editLoading = false;
            this.findPage(null);
            this.findDown();
        },
        //查询
        searchForm: function() {
            this.pageRequest.pageNum = "1";
            if (this.school_option) {
                this.school_option.forEach(SchoolItem => {
                    if (SchoolItem.schoolName === this.dataForm.schoolDictId) {
                        this.dataForm.schoolDictId = SchoolItem.id;
                    }
                });
            }
            if (this.userName) {
                this.userName.forEach(userItem => {
                    if (userItem.realName === this.dataForm.systemUserId) {
                        this.dataForm.systemUserId = userItem.id;
                    }
                });
            }
            this.findPage(null);
        },
        //新增页面展示
        handleAdd: function() {
            this.operation = true;
            this.dialogVisible = true;
            this.dataFormAdd = {
                userName: "",
                realName: "",
                phone: "",
                accountStatus: 1,
                acccountPassword: 111111,
                userType: 1
            };

            this.queryRole();
        },
        // 查询角色
        queryRole() {
            // roleType:1 三方、2：学校 3.分中心
            this.$api.role
                .queryFontRoleList({ userType: 3, roleType: 1 })
                .then(res => {
                    this.roles = res.userRoleList;
                });
        },
        //编辑页面展示
        handleEdit: function(params) {
            console.log(params);
            this.operation = false;
            this.dialogVisible = true;
            this.dataFormAdd = Object.assign({}, params.row);
            this.dataFormAdd.duty = this.dataFormAdd.duty.toString();
            this.changeAddOne(params.row.oneLevelDeptId);
            this.changeAddTwo(params.row.twoLevelDeptId);
            this.changeThreeFile(params.row.threeLevelDeptId);
        },
        //重置密码页面展示
        handleResetpass: function(params) {
            this.resetVisible = true;
            this.dataFormAdd = Object.assign({}, params.row);
        },

        //密码提交
        resetPwd: function() {
            this.$refs.password.validate(valid => {
                if (valid) {
                    this.$confirm("确认重置密码吗？", "提示", {}).then(() => {
                        this.data = {
                            password: this.dataFormAdd.userPassword,
                            id: this.dataFormAdd.id
                        };
                        this.editLoading = true;
                        let params = Object.assign({}, this.data);
                        this.$api.person.resetFontPwd(params).then(res => {
                            this.editLoading = false;
                            if (res.result == 1) {
                                this.$message({
                                    message: "成功！",
                                    type: "success"
                                });
                                this.resetVisible = false;
                                this.$refs["dataFormAdd"].resetFields();
                                this.findPage(null);
                            } else {
                                this.$message({
                                    message: res.msg,
                                    type: "error"
                                });
                            }
                            this.findPage(null);
                        });
                    });
                }
            });
        },
        //新增提交
        submitForm: function() {
            this.$refs.dataFormAdd.validate(valid => {
                if (valid) {
                    this.$confirm("确认提交吗？", "提示", {}).then(() => {
                        if (isMobile(this.dataFormAdd.phone)) {
                            this.editLoading = true;
                            let params = Object.assign({}, this.dataFormAdd);
                            this.$api.person.saveFontInfo(params).then(res => {
                                this.editLoading = false;
                                if (res.result == 1) {
                                    this.$message({
                                        message: res.msg,
                                        type: "success"
                                    });
                                    this.dialogVisible = false;
                                    this.$refs["dataFormAdd"].resetFields();
                                } else {
                                    this.$message({
                                        message: res.msg,
                                        type: "error"
                                    });
                                }
                                this.findPage(null);
                            });
                        } else {
                            this.$message({
                                message: "请输入正确的手机号！",
                                type: "error"
                            });
                        }
                    });
                }
            });
        },
        //编辑提交
        submitFormEdit: function() {
            this.$refs.dataFormAdd.validate(valid => {
                if (valid) {
                    this.$confirm("确认提交吗？", "提示", {}).then(() => {
                        this.editLoading = true;
                        let params = Object.assign({}, this.dataFormAdd);
                        this.$api.person.editFontInfo(params).then(res => {
                            this.editLoading = false;
                            if (res.result == 1) {
                                this.$message({
                                    message: res.msg,
                                    type: "success"
                                });
                                this.dialogVisible = false;
                                this.$refs["dataFormAdd"].resetFields();
                            } else {
                                this.$message({
                                    message: res.msg,
                                    type: "error"
                                });
                            }
                            this.findPage(null);
                        });
                    });
                }
            });
        },
        // 自动生成密码
        autopassword: function() {
            var password = "";
            var passLength = 8;
            var random = new Array(
                0,
                1,
                2,
                3,
                4,
                5,
                6,
                7,
                8,
                9,
                "A",
                "B",
                "C",
                "D",
                "E",
                "F",
                "G",
                "H",
                "I",
                "J",
                "K",
                "L",
                "M",
                "N",
                "O",
                "P",
                "Q",
                "R",
                "S",
                "T",
                "U",
                "V",
                "W",
                "X",
                "Y",
                "Z"
            );
            //随机数
            for (let i = 0; i < passLength; i++) {
                //循环操作
                var index = Math.floor(Math.random() * 36); //取得随机数的索引（0~35）
                password += random[index];
            }
            this.dataFormAdd.userPassword = password;
        },
        //switch开关
        changeSwitch: function(data) {
            let userId = data.row.id;
            this.$api.person.updateFontStatus({ id: userId }).then(res => {
                if (res.result == 1) {
                    this.$message({ message: res.msg, type: "success" });
                    this.$refs.dataForm.validate(valid => {
                        if (valid) {
                            this.data = {
                                userName: this.dataForm.userName,
                                realName: this.dataForm.realName,
                                oneLevelDeptId: this.dataForm.oneLevelDeptId,
                                twoLevelDeptId: this.dataForm.twoLevelDeptId,
                                threeLevelDeptId: this.dataForm
                                    .threeLevelDeptId,
                                roleId: this.dataForm.roleId,
                                phone: this.dataForm.phone,
                                email: this.dataForm.email,
                                duty: this.dataForm.duty,
                                demoAccount: this.dataForm.demoAccount,
                                accountStatus: this.dataForm.accountStatus
                            };
                            let params = Object.assign(
                                {},
                                this.data,
                                this.pageRequest
                            );
                        }
                    });
                } else {
                    this.$message({ message: res.msg, type: "error" });
                }
            });
        },
        //导出
        exportPerson: function() {
            this.$refs.dataForm.validate(valid => {
                if (valid) {
                    this.data = {
                        userName: this.dataForm.userName,
                        realName: this.dataForm.realName,
                        oneLevelDeptId: this.dataForm.oneLevelDeptId,
                        twoLevelDeptId: this.dataForm.twoLevelDeptId,
                        threeLevelDeptId: this.dataForm.threeLevelDeptId,
                        roleId: this.dataForm.roleId,
                        phone: this.dataForm.phone,
                        email: this.dataForm.email,
                        duty: this.dataForm.duty,
                        demoAccount: this.dataForm.demoAccount,
                        accountStatus: this.dataForm.accountStatus,
                        userType: 1
                    };
                    let params = Object.assign({}, this.data);
                    axios({
                        method: "get",
                        url: this.exportPersonUrl,
                        params: params
                    }).then(res => {
                        window.open(res.request.responseURL);
                    });
                }
            });
        },
        // 所属部门搜索
        querySearchAsync3(queryString, callback) {
            let restaurants = [{}];
            let results = "";
            this.$api.dropdown.deptLevel3().then(res => {
                let depatListJson = [];
                for (let i = 0; i < res.departmentInfoList.length; i++) {
                    let j = {};
                    j.name = res.departmentInfoList[i].deptName;
                    j.id = res.departmentInfoList[i].id;
                    depatListJson.push(j);
                }
                for (let i of depatListJson) {
                    i.value = i.name; //将想要展示的数据作为value
                }
                restaurants = depatListJson;
                results = queryString
                    ? restaurants.filter(this.createFilter3(queryString))
                    : restaurants;
                callback(results);
            });
        },
        createFilter3(queryString) {
            return restaurant => {
                return (
                    restaurant.name
                        .toLowerCase()
                        .indexOf(queryString.toLowerCase()) === 0
                );
            };
        },
        handleSelect3(item) {
            // this.queryBox.departmentId = item.id;
        },
        handleClearable(value) {
            if (this.userDerpatName == "") {
                this.managerAdd.departmentId = "";
            }
        },
        handleRelationSchool(params) {
            if (params.row.schoolDictId) {
                params.row.schoolDictId.split(",").forEach((item, index) => {
                    this.school_option.forEach(SchoolItem => {
                        if (
                            SchoolItem.id ==
                            params.row.schoolDictId.split(",")[index]
                        ) {
                            this.pageResultB.content.push(SchoolItem);
                        }
                    });
                });
            }
            this.schoolAddVisible = true;
            this.SubmitAddPopSelectDataId = params.row.id;
            this.findPage2(null);
        },
        handleBindManager(params) {
            this.managerAddVisible = true;
            this.managerAdd = params.row;
            this.departId_option.forEach(item => {
                if (item.id == params.row.systemUserIdDeptId) {
                    this.managerAdd.departId = item.deptName;
                }
            });
            // this.managerAdd.id=params.row.id
            if (
                !this.managerAdd.systemUserIdDeptId ||
                this.managerAdd.systemUserIdDeptId == ""
            ) {
                this.managerAddUserSelect = true;
            }
            if (this.managerAdd.systemUserIdDeptId) {
                this.$api.user
                    .queryUserListFont({
                        threeLevelDeptId: this.managerAdd.systemUserIdDeptId
                    })
                    .then(res => {
                        if (res.result == 1) {
                            this.userName = res.userInfoList;
                        }
                    });
            }
        },
        // 提交绑定大区经理
        submitBindManger() {
            this.$api.person
                .bindSystemUser({
                    id: this.managerAdd.id, //三方ID
                    systemUserId: this.managerAdd.systemUserId
                })
                .then(res => {
                    if (res.result == 1) {
                        this.$message({
                            message: res.msg.length != 0 ? res.msg : "绑定成功",
                            type: "success"
                        });
                        this.managerAddVisible = false;
                        this.loading = false;
                        this.findPage(null);
                    } else {
                        this.$message({
                            message: res.msg.length != 0 ? res.msg : "绑定失败",
                            type: "error"
                        });
                    }
                });
        },
        managerAddDeaprtChange(params) {
            this.managerAddUserSelect = false;
            this.$api.user
                .queryUserListFont({ threeLevelDeptId: params })
                .then(res => {
                    if (res.result == 1) {
                        this.userName = res.userInfoList;
                    }
                });
            this.managerAdd.systemUserId = "";
        },
        managerAddClose() {
            // this.managerAdd.departId=''
            // delete this.managerAdd.systemUserIdDeptId
        },
        managerAddUserChange(params) {}
    },
    mounted() {
        this.findDown();
    }
};
</script>
<style>
@import url("../../assets/queryBox.css");
</style>
<style>
.person input::-webkit-outer-spin-button,
.person input::-webkit-inner-spin-button {
    -webkit-appearance: none !important;
    margin: 0;
}
</style>
<style lang="scss">
.person1 .el-dialog__wrapper .el-form-item__content {
    margin-left: 100px;
}
</style>
<style lang="scss">
.columnsA-title {
    margin: 30px;
    font-size: 20px;
    font-weight: bold;
    text-align: left;
}
</style>
